package com.infocollect.common.exception;
import java.util.HashMap;
public class ResponseException extends RuntimeException {
    private static final long serialVersionUID = 1L;

    public static final Integer SUCCESS_CODE = 200;
    public static final Integer ERROR_CODE = 5002;
    public static final Integer ERROR_SQL_UNIQUE = 5003;
    public static final Integer ERROR_PARAM = 5004;
    public static final Integer INVALID_CLIENTID = 5005;

    public static final Integer ERROR_USER_INFO = 3100;
    public static final Integer ERROR_USER_FOUND = 3101;

    public static final Integer ERROR_TOKEN_NULL = 3201;
    public static final Integer ERROR_TOKEN_EXPRIE = 3202;

    public static final Integer ERROR_SENDSMS_OVERNUM = 4001;
    public static final Integer ERROR_VERCODE = 4002;
    public static final Integer ERROR_VERCODE_EXPRESS = 4003;
    public static final Integer ERROR_VERCODE_OVERNUM = 4004;

    public static HashMap<Integer, String> m_msgmap = new HashMap<Integer, String>();

    static {
        m_msgmap.put(SUCCESS_CODE, "操作成功");
        m_msgmap.put(ERROR_CODE, "系统内部错误");
        m_msgmap.put(ERROR_SQL_UNIQUE, "数据重复");
        m_msgmap.put(ERROR_PARAM, "参数错误");
        m_msgmap.put(INVALID_CLIENTID, "非法请求,请刷新页面重试");

        m_msgmap.put(ERROR_USER_INFO, "用户身份非法");
        m_msgmap.put(ERROR_USER_FOUND, "用户信息不存在");
        m_msgmap.put(ERROR_TOKEN_NULL, "用户身份获取失败");
        m_msgmap.put(ERROR_TOKEN_EXPRIE, "用户身份过期");

        m_msgmap.put(ERROR_SENDSMS_OVERNUM, "发送短信次数太频繁,请稍后再试");
        m_msgmap.put(ERROR_VERCODE, "验证码错误");
        m_msgmap.put(ERROR_VERCODE_EXPRESS, "验证码已失效，请重新发送");
        m_msgmap.put(ERROR_VERCODE_OVERNUM, "验证码次数过多，请重新发送");

    }

    public String status;
    public String message;
    public Integer code;
    public Object data;

    public ResponseException(int code) {
        this(code, m_msgmap.get(code));
    }

    public ResponseException(int code, String message) {
        this(code, message, null);
    }

    public ResponseException(int code, Object data) {
        this(code, m_msgmap.get(code), data, "ERR");
    }

    public ResponseException(int code, String message, Object data) {
        this(code, message, null, "ERR");
    }

    public ResponseException(int code, String message, Object data, String status) {
        super(code + "::" + message);
        this.message = message;
        this.code = code;
        this.data = data;
        this.status = status;
    }

    public String getStatus() {
        return status;
    }

    public String getMessage() {
        return message;
    }

    public Integer getCode() {
        return code;
    }

    public Object getData() {
        return data;
    }
}
